import axios from "axios";

class MJCrequest {
  constructor(config) {
    this.instance = axios.create(config);
    this.interceptors = config.interceptors;

    this.instance.interceptors.request.use(
      this.interceptors?.requestInterceptor,
      this.interceptors?.requestInterceptorCatch
    );

    this.instance.interceptors.response.use(
      this.interceptors?.responseInterceptor,
      this.interceptors?.responseInterceptorCatch
    );
  }
  request(config) {
    return new Promise((resolve, reject) => {
      this.instance.request(config).then((res) => {
        if (res.status != 200) {
          reject(res);
          return;
        }
        resolve(res);
      });
    });
  }
}

export default MJCrequest;
